package source;

import util.BigPrime;
import eduni.simjava.Sim_entity;
import eduni.simjava.Sim_port;
import eduni.simjava.distributions.Sim_negexp_obj;

	public class Source extends Sim_entity {

        private Sim_port out;
        
        private Sim_negexp_obj delay;
        
        private int packetSize;
        
        public Source(String name, double lambda, int packetSize) {
                super(name);

                out = new Sim_port("out");
                
                add_port(out);
                
                delay = new Sim_negexp_obj("Time to arrive one package", 1 / lambda, BigPrime.getSeed());
                this.packetSize = packetSize;
        }

        @Override
        public void body() {

                final int QUANTIDADE_DE_PACOTES = 10000;
                
                for (int i = 0; i < QUANTIDADE_DE_PACOTES; i++) {
                        double wait = delay.sample();
                        sim_schedule(out, wait, packetSize);
                        sim_hold(wait);
                }
        
                sim_schedule(out, 0, -1);
                
        }
        
}


